//                       .::::.
//                     .::::::::.
//                    :::::::::::
//                 ..:::::::::::'
//              '::::::::::::'
//                .::::::::::
//           '::::::::::::::..
//                ..::::::::::::.
//              ``::::::::::::::::
//               ::::``:::::::::'        .:::.
//              ::::'   ':::::'       .::::::::.
//            .::::'      ::::     .:::::::'::::.
//           .:::'       :::::  .:::::::::' ':::::.
//          .::'        :::::.:::::::::'      ':::::.
//         .::'         ::::::::::::::'         ``::::.
//     ...:::           ::::::::::::'              ``::.
//    ```` ':.          ':::::::::'                  ::::..
//                       '.:::::'                    ':'````..
package com.xw.service;

import com.github.pagehelper.PageHelper;
import com.google.common.collect.Maps;
import com.xw.dao.HistoryUploadVideosMapper;
import com.xw.dao.UserMapper;
import com.xw.model.User;
import com.xw.util.JsonData;
import com.xw.vo.HistoryUploadVideosVo;
import org.apache.commons.lang3.StringUtils;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import javax.annotation.Resource;
import java.util.List;
import java.util.Map;

@Service
@Transactional(rollbackFor = Exception.class)
public class HistoryUploadVideosServiceImpl implements HistoryUploadVideosService {

    @Resource
    private HistoryUploadVideosMapper uploadVideosMapper;
    @Resource
    private UserMapper userMapper;

    @Override
    public Map findHistoryByUserId(String userId, Integer page, Integer limit) {
        //验证是否拉黑
        if (!StringUtils.equals("-1",userId) && StringUtils.isNotBlank(userId)) {
            User user = userMapper.selectByPrimaryKey(userId);
            if (user.getUserStatus() == 2) {
                return JsonData.returnMap(811, "您的账号已被锁定");
            }
        }

        Map map = Maps.newHashMap();
        int totalCount = uploadVideosMapper.findHistoryByUserId(userId).size();
        if (page != null && limit != null){
            PageHelper.startPage(page,limit,false);
        }
        List<HistoryUploadVideosVo> list = uploadVideosMapper.findHistoryByUserId(userId);

        map.put("totalCount",totalCount);
        map.put("list",list);
        return JsonData.success(map);
    }
}
